#include "task.h"

#define Task5ms  0x01
#define Task10ms  0x02
#define Task20ms  0x04
#define Task100ms  0x08

u8 TaskFlag=0;
u16 TimerBase=0;

int main(void)
{
/*初始化*/
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    BSP_Init();
    Param_Init();
    /*死循环*/
     while(1){
        if(TaskFlag&Task5ms){
            Joint_Task_5ms();
            TaskFlag&=~Task5ms;
        }
        if(TaskFlag&Task10ms){
            TaskFlag&=~Task10ms;
        }
        if(TaskFlag&Task20ms){
            Control_Loop();
            TaskFlag&=~Task20ms;
        }
        if(TaskFlag&Task100ms){
            Send_Adc();
            TaskFlag&=~Task100ms;
        }
        if(RcvCnt){
            Data_Receive();
            RcvCnt--;
        }
    }
}

void SysTick_Handler(void)
{
    TimerBase++;
    TaskFlag|=Task5ms;
    if(TimerBase & 0x01)
        TaskFlag|=Task10ms;
    if(TimerBase%4==1)
        TaskFlag|=Task20ms;
    if(TimerBase>=20){
        TaskFlag|=Task100ms;
        TimerBase=0;
    }
}
